﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class admin_manage_permission : System.Web.UI.Page
    {

        protected DataSet GetPermissInform()
        {
            Maticsoft.BLL.Permissions PM = new Maticsoft.BLL.Permissions();
            DataSet currentDS = PM.GetAllList();
            DataView currentDV = currentDS.Tables[0].DefaultView;

            Grid1.DataSource = currentDV;
            Grid1.DataBind();
            return currentDS;
        
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
            }

            if(!IsPostBack)
            {
                GetPermissInform();
            }
        }

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            GetPermissInform();
        }

        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {


            if (e.CommandName == "ActionPermiss")
            {
                int index = e.RowIndex;
                DataSet currentDS = GetPermissInform();
                string currentP_Id = currentDS.Tables[0].Rows[index]["P_Id"].ToString();
                Maticsoft.BLL.Permissions PM = new Maticsoft.BLL.Permissions();
                Maticsoft.Model.Permissions PMInfrom = PM.GetModel(currentP_Id);
                PMInfrom.P_BelongType="已授权";
                if (!PM.Update(PMInfrom))
                {
                    Alert.Show("授权失败！", MessageBoxIcon.Information);               
                }
                GetPermissInform();
            
            }
            if (e.CommandName == "ActionCancel")
            {
                int index = e.RowIndex;
                DataSet currentDS = GetPermissInform();
                string currentP_Id = currentDS.Tables[0].Rows[index]["P_Id"].ToString();
                Maticsoft.BLL.Permissions PM = new Maticsoft.BLL.Permissions();
                Maticsoft.Model.Permissions PMInfrom = PM.GetModel(currentP_Id);
                PMInfrom.P_BelongType = "未授权";
                if (!PM.Update(PMInfrom))
                {
                    Alert.Show("取消授权失败！", MessageBoxIcon.Information);
                }
                GetPermissInform();
            
            }

        }
    }
}